
package guoan.service;

import guoan.core.dto.DataGridModel;
import guoan.core.dto.PageResponse;
import guoan.domain.AutoFormInput;
import guoan.repository.AutoFormInputRepository;
import guoan.repository.AutoFormValueRepository;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.google.common.collect.ImmutableMap;

@Service
@Transactional(readOnly = false)
public class AutoFormInputService extends PageSerivce<AutoFormInput> {
    protected final Logger log = LoggerFactory.getLogger(getClass());

    @Autowired
    private AutoFormInputRepository autoFormInputRepository;

    @Autowired
    private AutoFormValueRepository autoFormValueRepository;
    
    public void save(AutoFormInput autoFormInput){
        // TODO Auto-generated method stub
        autoFormInputRepository.save(autoFormInput);
    }

    public void delete(Long id){
        // TODO Auto-generated method stub
        autoFormInputRepository.delete(id);
        autoFormValueRepository.deleteByAutoFormInputId(id);
    }

    public PageResponse<AutoFormInput> page(Long autoFormId,
            DataGridModel dataGridModel){
        // TODO Auto-generated method stub
        Map<String, Long> paramMap = ImmutableMap.of("EQ_autoFormId",
                autoFormId);
        dataGridModel.setOrder("desc");
        dataGridModel.setSort("orderId");
        return pageResponse(autoFormInputRepository, paramMap, dataGridModel);
    }

    public AutoFormInput findOne(Long id){
        // TODO Auto-generated method stub
        return autoFormInputRepository.findOne(id);
    }

	public void deleteByFormid(String formid) {
		// TODO Auto-generated method stub
		autoFormValueRepository.deleteByFormid(formid);
	}
}
